package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.AgedmallAnnouncerBaseInfoMapper;
import org.linlinjava.litemall.db.domain.AgedmallAnnouncerBaseInfo;
import org.linlinjava.litemall.db.domain.AgedmallAnnouncerBaseInfoExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Service
public class AgedmallAnnouncerBaseInfoService {
    @Resource
    private AgedmallAnnouncerBaseInfoMapper agedmallAnnouncerBaseInfoMapper;

    public void add(AgedmallAnnouncerBaseInfo agedmallAnnouncerBaseInfo) {
        agedmallAnnouncerBaseInfo.setAddTime(LocalDateTime.now());
        agedmallAnnouncerBaseInfo.setUpdateTime(LocalDateTime.now());
        agedmallAnnouncerBaseInfoMapper.insertSelective(agedmallAnnouncerBaseInfo);
    }

    public AgedmallAnnouncerBaseInfo queryByStoreId(Integer storeId) {
        AgedmallAnnouncerBaseInfoExample example = new AgedmallAnnouncerBaseInfoExample();
        example.createCriteria().andDeletedEqualTo(false)
                .andStoreIdEqualTo(storeId);
        return agedmallAnnouncerBaseInfoMapper.selectOneByExample(example);
    }

    public AgedmallAnnouncerBaseInfo queryByStoreIdAndType(Integer storeId,Integer type) {
        AgedmallAnnouncerBaseInfoExample example = new AgedmallAnnouncerBaseInfoExample();
        example.createCriteria().andDeletedEqualTo(false)
                .andStoreIdEqualTo(storeId)
                .andTypeEqualTo(type);
        return agedmallAnnouncerBaseInfoMapper.selectOneByExample(example);
    }

    public AgedmallAnnouncerBaseInfo queryById(Integer id) {
        return agedmallAnnouncerBaseInfoMapper.selectByPrimaryKey(id);
    }

    public AgedmallAnnouncerBaseInfo queryByMac(String annoMac) {
        AgedmallAnnouncerBaseInfoExample example = new AgedmallAnnouncerBaseInfoExample();
        example.createCriteria().andDeletedEqualTo(false)
                .andAnnoMacEqualTo(annoMac);
        return agedmallAnnouncerBaseInfoMapper.selectOneByExample(example);
    }
}
